<template>
    <!--<el-dialog title=""  visible :show-close="false" :modal-append-to-body="false"  class="wrap">-->
	<el-dialog title="" width="40%" visible :show-close="false" :append-to-body="true" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
		 <div class="bt">休课</div>
        <el-form label-width="100px" class="form">
            <el-form-item label="学生名称">
                <el-input v-model="zwm" style="width: 60%;"></el-input>
                <el-button type="" size="mini" style='margin-left: 15px;' @click="cz()" >查找</el-button>
            </el-form-item>
            <el-form-item label="开始时间">
           		 <el-date-picker v-model="vbtime" :editable="false" type="date" class="code-search" placeholder="选择开始日期" @keyup.enter.native="search"> </el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间">
           		 <el-date-picker v-model="vetime" :editable="false" type="date" class="code-search" placeholder="选择开始日期" @keyup.enter.native="search"> </el-date-picker>
            </el-form-item>
            <el-form-item label="休课原因">
		        <el-input v-model="note" type="textarea" :rows="4" placeholder="请输入休学原因" class="select-block"></el-input>
	        </el-form-item>
        </el-form>
        <el-button type="primary" class="submit" @click="submit">休课</el-button>
        <el-button type="danger" class="submit" @click="cancel">退出</el-button>
    <AddComponent v-if="xsxxlist" @close="showadd"></AddComponent>
    </el-dialog>
</template>

<script type="text/javascript">
    import qs from 'qs'
    import AddComponent from './add'
    export default {
        props: ['params'],
        components: {
			AddComponent
		},
        data () {
            return {
            	vbtime:'',
            	vetime:'',
            	xsxxlist:false,
            	zwm:'',
               	note:'',
            }
        },
        created () {
//          this.form.zwm=this.params.row.zwm;
//            this.form.xsid=this.params.row.id;
        },
        methods: {
        	cz(){
        		this.xsxxlist = true
        	},
        	showadd(data){
        		if(data.data){
        			this.xsxxlist = false
	        		this.xsid = data.data.id
    	    		this.zwm = data.data.zwm
        		}else{
        			this.xsxxlist = false
        		}
        		
        	},
            submit () {
                this.$store.state.loading = true;
                if(!this.zwm) {
					this.$message.warning('请选择学生');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.vbtime) {
					this.$message.warning('请选择开始时间');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.vetime) {
					this.$message.warning('请选择结束时间');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.note) {
					this.$message.warning('请填写休课原因');
					this.$store.state.loading = false;
					return;
				}
	        var logininfo = JSON.parse(localStorage.logininfo);
	        var time1 = this.$.getLocalTimeNo0(Date.parse(this.vbtime));
			var time2 = this.$.getLocalTimeNo0(Date.parse(this.vetime));
				          var params3 = qs.stringify({
				                xsid: this.xsid+'',
				                note: this.note+'',
				                kssj:time1,
				                jssj:time2,
				                xxid: logininfo.xxid+'',
				                yhid: logininfo.id+''	
						});

            this.axios.post( this.$store.state.api + 'xxjl/insert', params3)
            .then( res => {
                if (res.data.code == 1) {
                    this.$emit('close',{type:'edit',cancel:false});
                    this.$message.success(res.data.msg);
                    this.$store.state.loading = false;
                }else{
                    this.$message.warning(res.data.msg);
                    this.$store.state.loading = false;
                }
            }).catch( res => {
              this.$message.danger("服务器异常");
                this.$store.state.loading = false;
            })
        },
            getTime (val) {
                this.form.time = val;
            },
            cancel () {
                this.$emit('close',{type:'edit',cancel:true})
            },
        }
    }
</script>

<style lang="less" scoped>
    .wrap {
        text-align: center;
    }
   .bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top:0;
			left:0;
			background: #50BFFF;
			margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
    .form {
        text-align: left;
        margin-top: 20px;

    }
    .input {
             display: inline-block;
         }
    .select-block {
        display: block;
        width: 85%;
    }
    .submit {
        width: 120px;
    }
</style>
